package com.cims.bpm.security.utils.msgdigest;

import java.security.MessageDigest;

import org.apache.log4j.Logger;

/**
 * 消息摘要：
 * sha256 的信息摘要算法
 *
 */
public class ShaUtils {
	
	private static Logger logger = Logger.getLogger(ShaUtils.class);
	
	/**
	 * 算法常量： SHA256
	 */
	private static final String ALGORITHM_SHA256 = "SHA-256";

	/**
	 * sha256 消息摘要
	 * @param message
	 * @return
	 */
	public static byte[] sha256(byte[] message) {
		MessageDigest md = null;
		try {
			md = MessageDigest.getInstance(ALGORITHM_SHA256);
			md.reset();
			md.update(message);
			byte[] result = md.digest();
			return result;
		} catch (Exception e) {
			logger.error("Fail: sha256 byte[] to byte[]", e);
		}
		return null;
	}

}
